
import { defineStore } from 'pinia'
// 用户数据信息
const useThemeStore = defineStore('theme', {
    state: () => {
        return {
            isDark: false,
            searcShow: {
                visible: true,
                text: '',
                title: '',
            }
        }
    },
    getters: {},
    actions: {
        changeTheme() {
            this.isDark = !this.isDark
            this.syncThemeToHtml()

        },
        syncThemeToHtml() {
            document.documentElement.classList.toggle('dark', this.isDark)
            document.documentElement.classList.toggle('light', !this.isDark)
        },
        updateSearchShow(newSettings) {
            this.searcShow = {
                ...this.searcShow, // 保留原有属性
                ...newSettings     // 覆盖新属性
            }
        }
    },
    persist: {
        enabled: true, //开启 enabled 之后，默认会对整个 Store 的 state 内容进行 sessionStorage 储存
        strategies: [
            {
                key: 'theme', 
                storage: localStorage, // 使用localStorage而不是默认的sessionStorage
            }
        ]
    }
})

export default useThemeStore

